<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>D3交互式数据可视化</title>
</head>
<body>
	<h4>映射--map</h4>
	<ul>
		<li>d3.map([object][,key])能构建映射</li>
		<li>map.has(key):指定的key存在返回true，反之则false</li>
		<li>map.get(key)：指定的key存在则返回该项，反之返回false</li>
		<li>map.set(key,value)：key存在则覆盖旧value，反之添加一个新的value,并返回新设置的value值</li>
		<li>map.remove(key)：key存在将此key和value删除，反之返回false</li>
		<li>map.keys():以数组的形式返回该map所有的key</li>
		<li>map.values()：以数组的形式返回所有的value</li>
		<li>map.entries()：以数组的形式返回所有的key和value</li>
		<li>map.forEach(function(key,value)):分别对改映射的每一项调用function函数</li>
		<li>map.empty():如果该映射为空，返回true，反之false</li>
		<li>map.size()：返回该映射的大小</li>
	</ul>
	<hr />
	<h4>集合--set</h4>
	<ul>
		<li>d3.set([array])：构建集合</li>
		<li>set.has(value)</li>
		<li>set.add(value)</li>
		<li>sey.remove(value)</li>
		<li>set.values()</li>
		<li>set.forEach(function)</li>
		<li>set.empty()</li>
		<li>set.size()</li>
		<li>集合中不允许出现相同的元素，有，只会保留其中一项</li>
	</ul>
	<h4>嵌套结构--nest</h4>
	<ul>
		<li></li>
	</ul>
	<script src="js/d3_3.5.7.js"></script>
	<script>
		var dataset = [
			{id:100,color:"red"},
			{id:101,color:"blue"},
			{id:102,color:"green"},
			{id:103,color:"pink"}
		]
		var map = d3.map(dataset,function(d) {
			return d.id
		})
		console.log(map.has(100),map.has(200));
		console.log(map.get(101));
		console.log(map.set(104,{id:104,color:"orange"}))
		console.log(map.remove(100))
		console.log(map.keys())
		console.log(map.values())
		console.log(map.entries())
		map.forEach(function(key,value) {
			console.log("the key is :" + key + ",the value is :" + value)
		})
		console.log(map.size())
		//nest
		var persons = [
			{id:100,name:'zhang',year:1987,home:'beijing'},
			{id:101,name:'zhang2',year:1997,home:'shanghai'},
			{id:102,name:'zhang3',year:1957,home:'guangzhou'},
			{id:103,name:'zhang4',year:1937,home:'chongqing'},
			{id:104,name:'zhang5',year:1947,home:'chnegdu'},
			{id:105,name:'zhang6',year:1987,home:'shenzhen'},
			{id:106,name:'zhang7',year:1967,home:'yibin'}
		]
		var nest = d3.nest().key(function(d) {
			return d.year
		}).key(function(d) {
			return d.home;
		})
		.entries(persons)
		console.log(nest)
	</script>
</body>
</html>